package com.person.yhzs.common.page;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 分页对象
 */
public class Page {
    public static final int PAGEINDEX = 1;
    public static final int PAGESIZE = 10;
    public static final int PAGE_MAX_SIZE = 100;

    protected Integer pageIndex = PAGEINDEX;
    protected Integer pageSize = PAGESIZE;

    public Page() {
        this.pageIndex = PAGEINDEX; 
        this.pageSize = PAGESIZE;
    }

    public Page(Integer pageIndex, Integer pageSize) {
        this.setPageIndex(pageIndex);
        this.setPageSize(pageSize);
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        if (pageIndex != null && pageIndex >= PAGEINDEX) {
            //大于或等于1 设置pageIndex值
            this.pageIndex = pageIndex;
        } else {
            //小于1 取默认值1
            this.pageIndex = PAGEINDEX;
        }
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        if (pageSize != null && pageSize > 0 && pageSize <= PAGE_MAX_SIZE) {
            this.pageSize = pageSize;
        } else {
            this.pageSize =  PAGESIZE;
        }
    }
    @JsonIgnore
    public long getOffset() {
        return (pageIndex - 1) * pageSize;
    }

}
